<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
session_start();
$CboNodo = $_REQUEST["CboNodo"];

$opcion = $_REQUEST["Opcion"];
//echo $opcion;
switch($opcion) {
    case 1:
        $imagen = "iconos/soloico_grabar.gif";
        $Titulo = "Modificar Organizaci&oacute;n";
        $Oculto = "<input type='hidden' name='Opcion' value='1'>";
        $Maximo = $_REQUEST["txtCodigo"];
        //$nombre = str_replace("", $replace, $subject)htmlentities($_REQUEST["nombreOrg"]);
        $nombre = preg_replace("[\\\]", "", htmlentities($_REQUEST["nombreOrg"]));
        break;
    case 2:
        $imagen = "iconos/soloico_eliminar.gif";
        $Titulo = "Eliminar Organizaci&oacute;n";
        $Oculto = "<input type='hidden' name='Opcion' value='2'>";
        break;
    case 3:
        $imagen = "iconos/soloico_grabar.gif";
        $Titulo = "Ingresar Organizaci&oacute;n";
        $Oculto = "<input type='hidden' name='Opcion' value='3'>";
        //'rw"",$_REQUEST["max")
        if (empty($_REQUEST["max"])) {
            $SoloSQL = "SELECT (max(id_tdl_datos)+1) FROM TDL_DATOS";
            $oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
                    $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
            $oConexion->EjecutarQuery($SoloSQL);
            $arrMax = $oConexion->getData("NUM");
            $Maximo = $arrMax[0][0];
            $oConexion->liberarResultado();
            $oConexion->Cerrar();
        }else
            $Maximo = $_REQUEST["max"];

        if (empty($_REQUEST["max_caja"])) {
            $SoloSQL = "SELECT (max(caja)+1) FROM LOCALIZACION";
            $oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
                    $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
            $oConexion->EjecutarQuery($SoloSQL);
            $arrMax = $oConexion->getData("NUM");
            $max_caja = is_null($arrMax[0][0])?1:$arrMax[0][0];
            $oConexion->liberarResultado();
            $oConexion->Cerrar();
        }else
            $max_caja = $_REQUEST["max_caja"];
        break;
}

$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
            $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
$sql = "SELECT id_etdl, nombre FROM ETDL WHERE id_tdl = 28 and fecha_eliminacion IS NULL order by nombre";
$id_etdl = SoloFun_ExecSqlFull($sql, $arrTipoOrganizacion, $oConexion);
$id_etdl = is_null($_REQUEST["cboTipo"])?$id_etdl:$_REQUEST["cboTipo"];

$sql2 = "select active_directory from solotb_usuario_infoadic where nu_usua like '%{$_REQUEST["txtCodigo"]}%'";
//echo $sql2;
$actived = EjecutaSentenciaSql($sql2);

if ($actived == "S")
    $valida = "novalida()";
else
    $valida = "ValidaDatos()";

SoloFun_ExecSql2 ($strsql, $ArrPerfil);

//'   rw"",ArrUsuario(4,0)
if (!empty($_REQUEST["CmbPerfil"])) $itemselec = $_REQUEST["CmbPerfil"];
//'rw"",itemselec
//'re
$StrCboPerfil = SoloFun_CargaCombo($ArrPerfil,"CmbPerfil","$CboDisabled",$itemselec," class='SoloStyle_Texto' style='width:200px'","");
?>
<html>
    <head>
        <title>MIES-WORKFLOW - Organizaciones</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <script type="text/JavaScript" src="PHPMailer/fun_generales.js"></script>
    </head>
    <body topmargin="0" leftmargin="0" onkeydown="checkKey();">
        <table cellpadding="0" cellspacing="0" style="width: 90%">
            <tr>
                <td><img src="templates/SoloTemplate_LogoCabecera.png" style="height: 50px" alt=""/></td>
                <td style="text-align:center" class="SoloStyle_TituloPaginas"><?php echo $Titulo; ?></td>
            </tr>
        </table>
        <form name="frm" action="organizaciones_Grabar.php?CboNodo=<?php echo $_REQUEST["CboNodo"]; ?>" method="POST">
            <?php echo $Oculto; ?>
            <table border="0" width="90%" align="center" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC">
                <tr>
                    <td><img src="iconos/soloico_salir.gif" border="1" alt="Regresar" style="cursor:hand" onClick="window.opener.location.reload(); window.close();" ><img src="<?php echo $imagen; ?>" border="1" alt="Grabar" style="cursor:hand" onClick="<?php echo $valida; ?>;"> </td>
            </table>
            <table border="0" width="90%" bordercolor="#CCCCCC" cellpadding="2" cellspacing="1" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta" width="25%"><b>Id Organizaci&oacute;n</b></td>
                    <td class="SoloStyle_EtiquetaCajas" width="75%"><?php echo $Maximo;?>
                        <input type="hidden" name="txtCodigo" maxlength="8" size="12" value="<?php echo $Maximo;?>" class="SoloStyle_Texto" readonly="true">
                        <input type="hidden" name="Opcion2"  value="<?php echo $opcion;?>">
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Tipo de Organizaci&oacute;n</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <select name="cboTipo">
                            <?php
                            foreach($arrTipoOrganizacion as $tipo) {
                                if($tipo[0] == $id_etdl)
                                    echo "<option value=\"{$tipo[0]}\" selected>{$tipo[1]}</option>";
                                else
                                    echo "<option value=\"{$tipo[0]}\">{$tipo[1]}</option>";
                            }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Nombre</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlength="250" size="43" id="ATxtNombre" name="ATxtNombre" class="SoloStyle_Texto" style="font-size: 14px" value="<?php echo Str2ProperCase($nombre);?>">
                    </td>
                </tr>
                <!--<tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <?php
                            $oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
                                    $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
                            $sql = "SELECT id_td,nombre FROM DEPARTAMENTO WHERE fecha_eliminacion is null";
                            //SoloFun_ExecSqlFull($sql, $arrDepartamentos, $oConexion);
                        ?>
                    </td>
                </tr>-->
                <!--<tr>
                    <td class="SoloStyle_Etiqueta"><b>No. Expediente</b> </td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <?php
                        if ($opcion == 3)
                            $Caja = $max_caja;
                        ?>
                        <input type="text" maxlength="20" size="12" id="ATxtCaja" name="ATxtCaja" class="SoloStyle_Texto" value="<?php echo $Caja;?>">
                    </td>
                </tr>-->
            </table>
        </form>
    </body>
</html>
<script type="text/javascript">
    function ValidaDatos(){
        document.frm.submit();
    }

    function novalida(){
        document.frm.submit();
    }

</script>

<?php
include "Includes/soloFun_ShowMessages.php";
?>
